package com.itheima.service.Impl;

import com.itheima.common.entity.PageResult;

import com.itheima.mapper.CheckGroupMapper;
import com.itheima.pojo.CheckGroup;
import com.itheima.service.CheckGroupService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class CheckGroupImpl implements CheckGroupService {

    @Autowired
    private CheckGroupMapper checkGroupMapper;

    /**
     * 新增检查项
     * @param checkGroup
     */
    public void insert(CheckGroup checkGroup) {
        checkGroupMapper.add(checkGroup);
    }


    /**
     * 查询全部数据
     * @param checkGroup
     * @return
     */
    public List<CheckGroup> list(CheckGroup checkGroup) {
        return checkGroupMapper.findAll(checkGroup);
    }

    /**
     * 根据id删除检查项
     * @param id
     */
    public void deleteById(Integer id) {
        checkGroupMapper.deleteById(id);
    }

    /**
     * 编辑检查项
     * @param checkGroup
     */
    public void edit(CheckGroup checkGroup) {
        checkGroupMapper.edit(checkGroup);
    }

    @Override
    public PageResult page(Integer currentPage, Integer pageSize) {
        //1.获取总记录数
        Long count = checkGroupMapper.count();
        //2.获取分页查询结果列表
        Integer start=(currentPage-1)*pageSize;
        List<CheckGroup> list= checkGroupMapper.page(start,pageSize);
        //3.封装PageResult对象
        PageResult pageResult = new PageResult(count, list);

        return pageResult;

    }

    @Override
    public CheckGroup findById(Integer id) {

        return checkGroupMapper.findById(id);
    }

    @Override
    public List<CheckGroup> getItemById(Integer id) {
        return checkGroupMapper.findCheckGroupIdsBySetmealId(id);
    }


}
